<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
var restoreString = function(s, indices) {
    let str = []
    for( var i = 0 ; i<indices.length ; i++ ){
        for ( var k = 0 ; k<indices.length ; k++ ){
            if( i == indices[k] ){
                str.splice(i,0,s[k])
            }
        }
    }
    str = str.toString()
    str = str.replace(/,/g,'')
    return str
};

var s = "codeleet"
var indices = [4,5,6,7,0,2,1,3]
console.log(restoreString(s, indices))
    </script>
</body>
</html>